package org.example.dyscript.dynamicscript;

import org.mvel2.MVEL;

import java.io.Serializable;
import java.util.Map;

public class MvelRule implements Rule {

  Serializable executeExpression;
  Serializable evaluateExpression;

  String executeScript = "ali_score > 100 " + "&& wx_score < 450 " + "&& !pd_living_province.contains(\"乌克兰\") "
      + "&& pd_census_province.contains(\"吉尔吉斯斯坦\")";

  String evaluateScript = "age > 18 && vip.contains(\"vip\")";

  public MvelRule() {
    executeExpression = MVEL.compileExpression(executeScript);
    evaluateExpression = MVEL.compileExpression(evaluateScript);
  }

  @Override
  public boolean execute(Map<String, Object> parameters) {
    return (boolean) MVEL.executeExpression(executeExpression, parameters);
  }

  @Override
  public boolean evaluate(Map<String, Object> parameters) {
    return (boolean) MVEL.executeExpression(evaluateExpression, parameters);
  }
}
